#include <iostream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <boost/foreach.hpp>

#define BOOST_TEST_MODULE PtreeExamples 
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(ReadXML_from_stringstream)
{
	#ifdef _DEBUG
		std::cout << "debug" << std::endl;
	#endif
	#ifdef NDEBUG
		std::cout << "release" << std::endl;
	#endif
	std::stringstream in;
	in << "<?xml ?><root><test /></root>";
	in << "<debug>\
		<filename>debug.log</filename>\
		<modules>\
		    <module>Finance</module>\
		    <module>Admin</module>\
		    <module>HR</module>\
		</modules>\
		<level>2</level>\
	</debug>";
	boost::property_tree::ptree pt;
	boost::property_tree::xml_parser::read_xml( in, pt);
	BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("debug.modules"))
        	std::cout << v.second.data() << std::endl;
}	
BOOST_AUTO_TEST_CASE(ReadXML_from_file)
{	
	boost::property_tree::ptree pt;
	boost::property_tree::xml_parser::read_xml("../test.xml", pt);
	BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("debug.modules"))
        	std::cout << v.second.data() << std::endl;
	BOOST_CHECK(2 == pt.get<int>("debug.level"));	
	try {
		pt.get<int>("debug.Level");	
	} catch(std::exception& e) {
		std::cout << e.what();
		std::cout << " try to read this using iptree(ingore case)" << std::endl;
	}
	boost::property_tree::iptree ipt;
	boost::property_tree::xml_parser::read_xml("../test.xml", ipt);
	BOOST_CHECK(2 == ipt.get<int>("Debug.Level"));
}
BOOST_AUTO_TEST_CASE(Using_wstring_version)
{
	std::wstringstream in(L"\u4E00 value"); 
	boost::property_tree::wptree wpt; 
	BOOST_REQUIRE_NO_THROW(boost::property_tree::read_info(in, wpt)); 
	std::wcout << wpt.get<std::wstring>(L"\u4E00") << std::endl;
}

